use super::bsl_list::BslList;
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct __BindgenBitfieldUnit<Storage> {
    storage: Storage,
}
impl<Storage> __BindgenBitfieldUnit<Storage> {
    #[inline]
    pub const fn new(storage: Storage) -> Self {
        Self { storage }
    }
}
impl<Storage> __BindgenBitfieldUnit<Storage>
where
    Storage: AsRef<[u8]> + AsMut<[u8]>,
{
    #[inline]
    fn extract_bit(byte: u8, index: usize) -> bool {
        let bit_index = if cfg!(target_endian = "big") {
            7 - (index % 8)
        } else {
            index % 8
        };
        let mask = 1 << bit_index;
        byte & mask == mask
    }
    #[inline]
    pub fn get_bit(&self, index: usize) -> bool {
        debug_assert!(index / 8 < self.storage.as_ref().len());
        let byte_index = index / 8;
        let byte = self.storage.as_ref()[byte_index];
        Self::extract_bit(byte, index)
    }
    #[inline]
    pub unsafe fn raw_get_bit(this: *const Self, index: usize) -> bool {
        debug_assert!(index / 8 < core::mem::size_of::<Storage>());
        let byte_index = index / 8;
        let byte = unsafe {
            *(core::ptr::addr_of!((*this).storage) as *const u8).offset(byte_index as isize)
        };
        Self::extract_bit(byte, index)
    }
    #[inline]
    fn change_bit(byte: u8, index: usize, val: bool) -> u8 {
        let bit_index = if cfg!(target_endian = "big") {
            7 - (index % 8)
        } else {
            index % 8
        };
        let mask = 1 << bit_index;
        if val {
            byte | mask
        } else {
            byte & !mask
        }
    }
    #[inline]
    pub fn set_bit(&mut self, index: usize, val: bool) {
        debug_assert!(index / 8 < self.storage.as_ref().len());
        let byte_index = index / 8;
        let byte = &mut self.storage.as_mut()[byte_index];
        *byte = Self::change_bit(*byte, index, val);
    }
    #[inline]
    pub unsafe fn raw_set_bit(this: *mut Self, index: usize, val: bool) {
        debug_assert!(index / 8 < core::mem::size_of::<Storage>());
        let byte_index = index / 8;
        let byte = unsafe {
            (core::ptr::addr_of_mut!((*this).storage) as *mut u8).offset(byte_index as isize)
        };
        unsafe { *byte = Self::change_bit(*byte, index, val) };
    }
    #[inline]
    pub fn get(&self, bit_offset: usize, bit_width: u8) -> u64 {
        debug_assert!(bit_width <= 64);
        debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
        debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
        let mut val = 0;
        for i in 0..(bit_width as usize) {
            if self.get_bit(i + bit_offset) {
                let index = if cfg!(target_endian = "big") {
                    bit_width as usize - 1 - i
                } else {
                    i
                };
                val |= 1 << index;
            }
        }
        val
    }
    #[inline]
    pub unsafe fn raw_get(this: *const Self, bit_offset: usize, bit_width: u8) -> u64 {
        debug_assert!(bit_width <= 64);
        debug_assert!(bit_offset / 8 < core::mem::size_of::<Storage>());
        debug_assert!((bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::<Storage>());
        let mut val = 0;
        for i in 0..(bit_width as usize) {
            if unsafe { Self::raw_get_bit(this, i + bit_offset) } {
                let index = if cfg!(target_endian = "big") {
                    bit_width as usize - 1 - i
                } else {
                    i
                };
                val |= 1 << index;
            }
        }
        val
    }
    #[inline]
    pub fn set(&mut self, bit_offset: usize, bit_width: u8, val: u64) {
        debug_assert!(bit_width <= 64);
        debug_assert!(bit_offset / 8 < self.storage.as_ref().len());
        debug_assert!((bit_offset + (bit_width as usize)) / 8 <= self.storage.as_ref().len());
        for i in 0..(bit_width as usize) {
            let mask = 1 << i;
            let val_bit_is_set = val & mask == mask;
            let index = if cfg!(target_endian = "big") {
                bit_width as usize - 1 - i
            } else {
                i
            };
            self.set_bit(index + bit_offset, val_bit_is_set);
        }
    }
    #[inline]
    pub unsafe fn raw_set(this: *mut Self, bit_offset: usize, bit_width: u8, val: u64) {
        debug_assert!(bit_width <= 64);
        debug_assert!(bit_offset / 8 < core::mem::size_of::<Storage>());
        debug_assert!((bit_offset + (bit_width as usize)) / 8 <= core::mem::size_of::<Storage>());
        for i in 0..(bit_width as usize) {
            let mask = 1 << i;
            let val_bit_is_set = val & mask == mask;
            let index = if cfg!(target_endian = "big") {
                bit_width as usize - 1 - i
            } else {
                i
            };
            unsafe { Self::raw_set_bit(this, index + bit_offset, val_bit_is_set) };
        }
    }
}
pub const BSL_ASN1_CLASS_UNIVERSAL: u32 = 0;
pub const BSL_ASN1_CLASS_APPLICATION: u32 = 64;
pub const BSL_ASN1_CLASS_CTX_SPECIFIC: u32 = 128;
pub const BSL_ASN1_CLASS_PRIVATE: u32 = 192;
pub const BSL_ASN1_TAG_CONSTRUCTED: u32 = 32;
pub const BSL_ASN1_TAG_BOOLEAN: u32 = 1;
pub const BSL_ASN1_TAG_INTEGER: u32 = 2;
pub const BSL_ASN1_TAG_BITSTRING: u32 = 3;
pub const BSL_ASN1_TAG_OCTETSTRING: u32 = 4;
pub const BSL_ASN1_TAG_NULL: u32 = 5;
pub const BSL_ASN1_TAG_OBJECT_ID: u32 = 6;
pub const BSL_ASN1_TAG_OBJECT_DESCP: u32 = 7;
pub const BSL_ASN1_TAG_INSTANCE_OF: u32 = 8;
pub const BSL_ASN1_TAG_REAL: u32 = 9;
pub const BSL_ASN1_TAG_ENUMERATED: u32 = 10;
pub const BSL_ASN1_TAG_EMBEDDED_PDV: u32 = 11;
pub const BSL_ASN1_TAG_UTF8STRING: u32 = 12;
pub const BSL_ASN1_TAG_RALATIVE_ID: u32 = 13;
pub const BSL_ASN1_TAG_TIME: u32 = 14;
pub const BSL_ASN1_TAG_SEQUENCE: u32 = 16;
pub const BSL_ASN1_TAG_SET: u32 = 17;
pub const BSL_ASN1_TAG_PRINTABLESTRING: u32 = 19;
pub const BSL_ASN1_TAG_TELETEXSTRING: u32 = 20;
pub const BSL_ASN1_TAG_T61STRING: u32 = 20;
pub const BSL_ASN1_TAG_IA5STRING: u32 = 22;
pub const BSL_ASN1_TAG_UTCTIME: u32 = 23;
pub const BSL_ASN1_TAG_GENERALIZEDTIME: u32 = 24;
pub const BSL_ASN1_TAG_BMPSTRING: u32 = 30;
pub const BSL_ASN1_TAG_CHOICE: u32 = 193;
pub const BSL_ASN1_TAG_ANY: u32 = 194;
pub const BSL_ASN1_TAG_EMPTY: u32 = 0;
pub const BSL_ASN1_FLAG_OPTIONAL: u32 = 1;
pub const BSL_ASN1_FLAG_DEFAULT: u32 = 2;
pub const BSL_ASN1_FLAG_HEADERONLY: u32 = 4;
pub const BSL_ASN1_FLAG_SAME: u32 = 8;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _BSL_ASN1_Buffer {
    pub tag: u8,
    pub len: u32,
    pub buff: *mut u8,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of _BSL_ASN1_Buffer"][::std::mem::size_of::<_BSL_ASN1_Buffer>() - 16usize];
    ["Alignment of _BSL_ASN1_Buffer"][::std::mem::align_of::<_BSL_ASN1_Buffer>() - 8usize];
    ["Offset of field: _BSL_ASN1_Buffer::tag"]
        [::std::mem::offset_of!(_BSL_ASN1_Buffer, tag) - 0usize];
    ["Offset of field: _BSL_ASN1_Buffer::len"]
        [::std::mem::offset_of!(_BSL_ASN1_Buffer, len) - 4usize];
    ["Offset of field: _BSL_ASN1_Buffer::buff"]
        [::std::mem::offset_of!(_BSL_ASN1_Buffer, buff) - 8usize];
};
pub type BSL_ASN1_Buffer = _BSL_ASN1_Buffer;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _BSL_ASN1_BitString {
    pub buff: *mut u8,
    pub len: u32,
    pub unusedBits: u8,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of _BSL_ASN1_BitString"][::std::mem::size_of::<_BSL_ASN1_BitString>() - 16usize];
    ["Alignment of _BSL_ASN1_BitString"][::std::mem::align_of::<_BSL_ASN1_BitString>() - 8usize];
    ["Offset of field: _BSL_ASN1_BitString::buff"]
        [::std::mem::offset_of!(_BSL_ASN1_BitString, buff) - 0usize];
    ["Offset of field: _BSL_ASN1_BitString::len"]
        [::std::mem::offset_of!(_BSL_ASN1_BitString, len) - 8usize];
    ["Offset of field: _BSL_ASN1_BitString::unusedBits"]
        [::std::mem::offset_of!(_BSL_ASN1_BitString, unusedBits) - 12usize];
};
pub type BSL_ASN1_BitString = _BSL_ASN1_BitString;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _BSL_ASN1_TemplateItem {
    pub tag: u8,
    pub _bitfield_align_1: [u8; 0],
    pub _bitfield_1: __BindgenBitfieldUnit<[u8; 1usize]>,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of _BSL_ASN1_TemplateItem"][::std::mem::size_of::<_BSL_ASN1_TemplateItem>() - 2usize];
    ["Alignment of _BSL_ASN1_TemplateItem"]
        [::std::mem::align_of::<_BSL_ASN1_TemplateItem>() - 1usize];
    ["Offset of field: _BSL_ASN1_TemplateItem::tag"]
        [::std::mem::offset_of!(_BSL_ASN1_TemplateItem, tag) - 0usize];
};
impl _BSL_ASN1_TemplateItem {
    #[inline]
    pub fn flags(&self) -> u8 {
        unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 5u8) as u8) }
    }
    #[inline]
    pub fn set_flags(&mut self, val: u8) {
        unsafe {
            let val: u8 = ::std::mem::transmute(val);
            self._bitfield_1.set(0usize, 5u8, val as u64)
        }
    }
    #[inline]
    pub unsafe fn flags_raw(this: *const Self) -> u8 {
        unsafe {
            ::std::mem::transmute(<__BindgenBitfieldUnit<[u8; 1usize]>>::raw_get(
                ::std::ptr::addr_of!((*this)._bitfield_1),
                0usize,
                5u8,
            ) as u8)
        }
    }
    #[inline]
    pub unsafe fn set_flags_raw(this: *mut Self, val: u8) {
        unsafe {
            let val: u8 = ::std::mem::transmute(val);
            <__BindgenBitfieldUnit<[u8; 1usize]>>::raw_set(
                ::std::ptr::addr_of_mut!((*this)._bitfield_1),
                0usize,
                5u8,
                val as u64,
            )
        }
    }
    #[inline]
    pub fn depth(&self) -> u8 {
        unsafe { ::std::mem::transmute(self._bitfield_1.get(5usize, 3u8) as u8) }
    }
    #[inline]
    pub fn set_depth(&mut self, val: u8) {
        unsafe {
            let val: u8 = ::std::mem::transmute(val);
            self._bitfield_1.set(5usize, 3u8, val as u64)
        }
    }
    #[inline]
    pub unsafe fn depth_raw(this: *const Self) -> u8 {
        unsafe {
            ::std::mem::transmute(<__BindgenBitfieldUnit<[u8; 1usize]>>::raw_get(
                ::std::ptr::addr_of!((*this)._bitfield_1),
                5usize,
                3u8,
            ) as u8)
        }
    }
    #[inline]
    pub unsafe fn set_depth_raw(this: *mut Self, val: u8) {
        unsafe {
            let val: u8 = ::std::mem::transmute(val);
            <__BindgenBitfieldUnit<[u8; 1usize]>>::raw_set(
                ::std::ptr::addr_of_mut!((*this)._bitfield_1),
                5usize,
                3u8,
                val as u64,
            )
        }
    }
    #[inline]
    pub fn new_bitfield_1(flags: u8, depth: u8) -> __BindgenBitfieldUnit<[u8; 1usize]> {
        let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize]> = Default::default();
        __bindgen_bitfield_unit.set(0usize, 5u8, {
            let flags: u8 = unsafe { ::std::mem::transmute(flags) };
            flags as u64
        });
        __bindgen_bitfield_unit.set(5usize, 3u8, {
            let depth: u8 = unsafe { ::std::mem::transmute(depth) };
            depth as u64
        });
        __bindgen_bitfield_unit
    }
}
pub type BSL_ASN1_TemplateItem = _BSL_ASN1_TemplateItem;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _BSL_ASN1_Template {
    pub templItems: *mut BSL_ASN1_TemplateItem,
    pub templNum: u32,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of _BSL_ASN1_Template"][::std::mem::size_of::<_BSL_ASN1_Template>() - 16usize];
    ["Alignment of _BSL_ASN1_Template"][::std::mem::align_of::<_BSL_ASN1_Template>() - 8usize];
    ["Offset of field: _BSL_ASN1_Template::templItems"]
        [::std::mem::offset_of!(_BSL_ASN1_Template, templItems) - 0usize];
    ["Offset of field: _BSL_ASN1_Template::templNum"]
        [::std::mem::offset_of!(_BSL_ASN1_Template, templNum) - 8usize];
};
pub type BSL_ASN1_Template = _BSL_ASN1_Template;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _BSL_ASN1_DecodeListParam {
    pub layer: u32,
    pub expTag: *mut u8,
}
#[allow(clippy::unnecessary_operation, clippy::identity_op)]
const _: () = {
    ["Size of _BSL_ASN1_DecodeListParam"]
        [::std::mem::size_of::<_BSL_ASN1_DecodeListParam>() - 16usize];
    ["Alignment of _BSL_ASN1_DecodeListParam"]
        [::std::mem::align_of::<_BSL_ASN1_DecodeListParam>() - 8usize];
    ["Offset of field: _BSL_ASN1_DecodeListParam::layer"]
        [::std::mem::offset_of!(_BSL_ASN1_DecodeListParam, layer) - 0usize];
    ["Offset of field: _BSL_ASN1_DecodeListParam::expTag"]
        [::std::mem::offset_of!(_BSL_ASN1_DecodeListParam, expTag) - 8usize];
};
pub type BSL_ASN1_DecodeListParam = _BSL_ASN1_DecodeListParam;
pub type BSL_ASN1_DecTemplCallBack = ::std::option::Option<
    unsafe extern "C" fn(
        type_: i32,
        idx: u32,
        data: *mut ::std::os::raw::c_void,
        expVal: *mut ::std::os::raw::c_void,
    ) -> i32,
>;
pub type BSL_ASN1_ParseListAsnItem = ::std::option::Option<
    unsafe extern "C" fn(
        layer: u32,
        asn: *mut BSL_ASN1_Buffer,
        cbParam: *mut ::std::os::raw::c_void,
        list: *mut BslList,
    ) -> i32,
>;
unsafe extern "C" {
    pub fn BSL_ASN1_DecodeTagLen(
        tag: u8,
        encode: *mut *mut u8,
        encLen: *mut u32,
        valLen: *mut u32,
    ) -> i32;
}
unsafe extern "C" {
    pub fn BSL_ASN1_EncodeTemplate(
        templ: *mut BSL_ASN1_Template,
        asnArr: *mut BSL_ASN1_Buffer,
        arrNum: u32,
        encode: *mut *mut u8,
        encLen: *mut u32,
    ) -> i32;
}
unsafe extern "C" {
    pub fn BSL_ASN1_DecodeTemplate(
        templ: *mut BSL_ASN1_Template,
        decTemlCb: BSL_ASN1_DecTemplCallBack,
        encode: *mut *mut u8,
        encLen: *mut u32,
        asnArr: *mut BSL_ASN1_Buffer,
        arrNum: u32,
    ) -> i32;
}
unsafe extern "C" {
    pub fn BSL_ASN1_EncodeListItem(
        tag: u8,
        listSize: u32,
        templ: *mut BSL_ASN1_Template,
        asnArr: *mut BSL_ASN1_Buffer,
        arrNum: u32,
        out: *mut BSL_ASN1_Buffer,
    ) -> i32;
}
unsafe extern "C" {
    pub fn BSL_ASN1_DecodeListItem(
        param: *mut BSL_ASN1_DecodeListParam,
        asn: *mut BSL_ASN1_Buffer,
        parseListItemCb: BSL_ASN1_ParseListAsnItem,
        cbParam: *mut ::std::os::raw::c_void,
        list: *mut BslList,
    ) -> i32;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct __locale_data {
    pub _address: u8,
}
